package mest.service.Modeling.Impl;

import com.alibaba.fastjson.JSON;
import mest.VO.hank.model.employeeFileModel;
import mest.dao.Modeling.IemployeeFileDao;
import mest.entity.apart_file;
import mest.entity.employee_file;
import mest.service.Modeling.IemployeeFileService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-11-15 22:46
 */
@Service
@Transactional(rollbackFor=Exception.class)
public class employeeFileServiceImpl implements IemployeeFileService {


    @Resource
    private IemployeeFileDao iefd;

    @Override
    public String insertEmployeeFile(employee_file ef,String theirDb) {
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            iefd.insertEmployeeFile(ef, theirDb);
            map.put("code",0);
            map.put("msg","添加成功");
            return JSON.toJSONString(map);
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
                map.put("msg","编码重复");
                return JSON.toJSONString(map);
            }
            map.put("msg", "添加失败");
            return JSON.toJSONString(map);
        }
    }

    @Override
    public int selectCount( String theirDb) {
        return iefd.selectCount( theirDb);
    }

    @Override
    public List<employee_file> findEmployeeFilePage(Integer index, Integer pageSize,String theirDb) {
        return iefd.findEmployeeFilePage((index-1)*pageSize,pageSize, theirDb);
    }




    //删除方法
    @Override
    public int delModel(Integer id,String theirDb) {
        return iefd.delModel(id,theirDb);
    }

    @Override
    public List<employeeFileModel> queryAll(Integer index, Integer pageSize, String name,String theirDb) {
        return iefd.queryAllModel((index-1)*pageSize, pageSize, name, theirDb);
    }

    @Override
    public int findCount(String name,String theirDb) {
        return iefd.findCount(name, theirDb);
    }


    @Override
    public String updateByOne(employee_file record,String theirDb) {
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            iefd.updateByPrimaryKeySelective(record, theirDb);
            map.put("code",0);
            map.put("msg","添加成功");
        }catch (Exception e){
            e.printStackTrace();
            if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
                map.put("msg","编码重复");
                return JSON.toJSONString(map);
            }
            map.put("msg","添加失败");
        }
        return JSON.toJSONString(map);
    }




}
